<?php
session_start();

class Index extends MY_Controller{
	private $status = true;
	private $token = '';
	
	function __construct(){
		parent::__construct();
		Sys::loadLanguage($this->params['lang'],'panel');
	}
	
	public function _remap($method, $params){
		$res = $this->checkAccessToken();
		
		$this->load->model('user_model');
		$info = $this->user_model->getInfoUser($this->params);
		$this->params['usr_info'] = $info['user'];
		
		if($res && $this->params['usr_info']['status']==1){
			if($this->params['usr_info']['tipo']=='admin'){
				if($method=="index"){
		    		$this->index();
				}
			}
			else if($this->params['usr_info']['tipo']=='usuario'){
				if($method=="index"){
		    		$this->user();
				}
			}
		}
		else if(isset($_COOKIE["p_goto"])){ //redireccionar a alguna url despues de logearse
			
			$url = $_COOKIE["p_goto"];
			setcookie('p_goto', '', time()-1200, '/');
			header("Location: ".$url);
		}
		else{
	    	header('Location:'.Sys::$url_base.$this->params['lang_url']);
		}
		
	}
	
	/**
	 * 
	 * 	MUESTRA EL MENU DEL ADMINISTRADOR
	 */
	public function index(){
		$this->carabiner->css('dev/style.css');
		$this->carabiner->css('dev/panel/style.css');
		
		$js	= array(
					array('dev/libs/jquery.js'),
					array('dev/libs/jquery.tools.min.js'),
					array('dev/panel/general.js')
				);
		$this->carabiner->js($js);


		$this->params['lang_txt_seccion'] = lang('txt_seccion_index');
		$this->params['seo'] = array(
			'title' 		=> ''.Sys::$title_web,
			'description' 	=> ''
		);
		
		$this->load->view('interface/header',$this->params);
		$this->load->view('interface/panel/content',$this->params);
		$this->load->view('interface/panel/aside',$this->params);
		$this->load->view('interface/footer',$this->params);
	}
	
	/**
	 * 
	 * 	MUESTRA EL MENU DEL USUARIO
	 */
	public function user(){
		$this->carabiner->css('dev/style.css');
		$this->carabiner->css('dev/panel/style.css');
		
		$js	= array(
					array('dev/libs/jquery.js'),
					array('dev/libs/jquery.tools.min.js'),
					array('dev/panel/general.js')
				);
		$this->carabiner->js($js);
		
		$this->params['lang_txt_seccion'] = lang('txt_seccion_index_usr').' '.$this->params['usr_info']['nombre'];
		$this->params['seo'] = array(
			'title' 		=> ''.Sys::$title_web,
			'description' 	=> ''
		);
		
		$this->load->view('interface/header',$this->params);
		$this->load->view('interface/panel/content',$this->params);
		$this->load->view('interface/panel/user/aside',$this->params);
		$this->load->view('interface/footer',$this->params);
	}
	
}